<!DOCTYPE html>
<html>
<head>
<title>treatInfoIframe.html</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

</head>
<style type="text/css">
body {
	width: 100%;
	height: 100%;
	background: #fff;
}

select {
	height: 38px;
	line-height: 1.3;
	line-height: 38px\9;
	border-width: 1px;
	border-style: solid;
	background-color: #fff;
	border-radius: 2px;
	width: 100%;
}

#btn_search {
	margin-top: 8px;
	margin-left: -25px;
}

.row {
	margin-top: 10px;
}
/*表格样式*/
</style>
<link rel="stylesheet" href="/Hospital/lib/layui-v2.1.6/layui/css/layui.css" media="all">
<body>
	<div class="layui-form layui-container" style="">
		<div id="div_client" class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1 layui-col-sm2 layui-col-sm-offset1 layui-col-md2 layui-col-md-offset2">
				<span class="layui-form-label">执行者: </span>
			</div>
			<div class="layui-col-xs5 layui-col-sm3 layui-col-md2">
				<select id="sel_excutor" name="sel_excutor" class="layui-input-inline" lay-filter="sel_excutor">
				</select>
			</div>
		</div>
	</div>
	
	<fieldset id="fs_excutorInfo" style="margin:25px">
		<legend>执行者信息</legend>
		<div id="div_clientInfo">
			<div class="layui-row row" style="display:none;">
				<div class="layui-col-xs4 layui-col-xs-offset0 layui-col-sm2 layui-col-sm-offset1 layui-col-md2 layui-col-md-offset2">
					<span class="layui-form-label">执行者Id: </span>
				</div>
				<div class="layui-col-xs5 layui-col-sm3 layui-col-md2 ">
					<input id="excutorId" class="layui-input" type="text" disabled="">
				</div>
			</div>
			<div class="layui-row row">
				<div class="layui-col-xs4 layui-col-xs-offset0 layui-col-sm2 layui-col-sm-offset1 layui-col-md2 layui-col-md-offset2">
					<span class="layui-form-label">姓名: </span>
				</div>
				<div class="layui-col-xs5 layui-col-sm3 layui-col-md2">
					<input id="excutorName" class="layui-input" type="text" disabled>
				</div>
			</div>
			<div class="layui-row row">
				<div class="layui-col-xs4 layui-col-xs-offset0 layui-col-sm2 layui-col-sm-offset1 layui-col-md2 layui-col-md-offset2">
					<span class="layui-form-label">工号: </span>
				</div>
				<div class="layui-col-xs5 layui-col-sm3 layui-col-md2">
					<input id="excutorCode" class="layui-input" type="text" disabled>
				</div>
			</div>
		</div>
	</fieldset>
</body>
<script src="/Hospital/lib/jquery.min.js" charset="utf-8"></script>
<script src="/Hospital/lib/layui-v2.1.6/layui/layui.js" charset="utf-8"></script>
<script>
	var mcDetail = JSON.parse(localStorage.getItem("medicalCardDetail")); //治疗卡信息
	localStorage.removeItem("medicalCardDetail");
	
	layui.use([ "table","form" ], function() {
		var table = layui.table;
		var form = layui.form;
		var $ = layui.jquery;
		initFrame();

		function initFrame() {
			btnSearchEvent();//搜索按钮监听事件
			initExcutorSelect();//初始化执行者下拉框
			selectEvent();//执行者下拉框变换事件
		}

		//搜索按钮监听事件
		function btnSearchEvent() {
			$("#btn_search").on("click", function() {
				var param = {
					identity : $("#client").val()
				};
				$.ajax({
					type : "post",
					url : "/Hospital/userController/getClientByIdentity",
					data : param,
					success : function(response) {
						//console.log("btnSearchEvent.response");
						//console.log(response);
						var data = response.result;
						if (data.length == 0) {
							setClinetInfoEmpty();
							layer.msg("找不到用户", {
								icon : 2,
								time : 1000,
							});
							return;
						}
						$("#clientId").val(data[0].clientId);
						$("#name").val(data[0].name);
						$("#sex").val(data[0].sex);
						$("#phone").val(data[0].phone);
					}
				});
			});
		}
		//初始化执行者下拉框
		function initExcutorSelect() {
			var loginUser = JSON.parse(localStorage.getItem("loginUser"));
			var param = {
				clinicId : loginUser.clinicId
			};
			console.log("initExcutorSelect.param");
			console.log(param);
			$.ajax({
				type : "post",
				data : param,
				url : "/Hospital/userController/getClinicEmployee",
				success : function(response) {
					var result = response.result;
					//console.log("createTreatInfo.getClinicEmployee.result");
					//console.log(result);
					for (var i = 0; i < result.length; i++) {
						var excutorId = result[i].employeeId;
						var excutorCode = result[i].employeeCode;
						var name = result[i].name;
						//console.log("createTreatInfo.getClinicEmployee.employeeCode");
						//console.log(excutorCode);
						$("#sel_excutor").append("<option value="+excutorId+" data-code="+excutorCode+ ">" + name + "</option>");
					}
					form.render();
					initExcutorInfo();
				}
			});
		}
		
		//科室下拉框监听事件
		function selectEvent() {
			form.on('select(sel_excutor)', function(data) {
				initExcutorInfo();
			});
		}
		
		function initExcutorInfo() {
			$("#excutorId").val($("#sel_excutor").val());
			$("#excutorName").val($("#sel_excutor").find("option:selected").text());
			$("#excutorCode").val($("#sel_excutor").find("option:selected").attr("data-code"));
		}
	});

	//设置病人信息为空
	function setClinetInfoEmpty() {
		$("#clientId").val("");
		$("#name").val("");
		$("#sex").val("");
		$("#phone").val("");
	}

	//获取数据内容
	function getParam() {
		var param = {};
		param = {
			clientId : mcDetail.clientId,
			projectId : mcDetail.projectId,
			excutorId : $("#excutorId").val(),
		};
		return param;
	}
</script>
</html>
